<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link th:href="@{/js/el/element.css}" rel="stylesheet"  type="text/css"/>
    <script th:src="@{/js/vue.min.js}" type="text/javascript"></script>
    <script th:src="@{/js/el/element.js}" type="text/javascript"></script>
    <script th:src="@{/js/axios.js}" type="text/javascript"></script>
    <style>
        body{
            background-image:url("/css/img/haitan.jpg");
            /*background-color: #a0cfff;*/
        }
        .myLogin {

            width: 300px;
            /*绝对定位的方式*/
            position: absolute;
            /*定位登录div的位置*/
            left: 50%;
            top: 40%;
            transform: translate(-40%, -60%);
            /*内边距*/
            padding-top: 20px;
            padding-left: 10px;
            padding-right: 10px;
        }
    </style>
</head>
<body>
<div>
    <div class="myLogin" id="app">
        <h2 style="text-align: center">&nbsp;请登录&nbsp;</h2>
        <div style="text-align: center">
            <el-form label-position="right" label-width="80px" :model="user">
                <el-form-item label="账号">
                    <el-input placeholder="请输入用户名"
                              v-model="user.username" clearable></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input placeholder="请输入密码"
                              v-model="user.password" show-password></el-input>
                </el-form-item>
                <el-button type="primary" v-on:click="goLogin()">登录</el-button>
            </el-form>
        </div>
    </div>
</div>
</body>
<script>
    new Vue({
        el: "#app",
        data:{
            user:{username:"",password:""},
        },
        methods:{
            goLogin(){
                var that = this;
                console.log(this.user)

                axios({
                    url:"/doLogin",
                    method:"post",
                    // resp.setContentType("application/json;charset=utf-8");
                    headers:{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params:this.user
                }).then(function (response) {
                    console.log(response)
                    if(response.data.msg==0){
                        that.$message({
                            showClose: true,
                            offset: 100,
                            message: "账户名或密码输入错误，登陆失败",
                            type: 'error'
                        })
                        return;
                    }
                    that.$message({
                        showClose: true,
                        offset: 100,
                        message: "登录成功",
                        type: 'success'
                    });
                    window.location.href = response.data.action  //转发
                })
            }
        },
        mounted: function(){

        }
    })
</script>
</html>